#!/usr/bin/perl

use strict;
use warnings;

package Navalha;

use Net::Server::Multiplex;
use Getopt::Std;
use Cache::Memcached;
use Sys::Syslog;
use POSIX;
our @ISA = qw(Net::Server::Multiplex);

open (LOG,">/tmp/navalha");

my %opts; 
getopts('c:d:', \%opts);

my $memcached = new Cache::Memcached {
	'servers' => [
		"localhost:11212",
		"localhost:11213",
	],
};

my %request;
my %data;

my $navalha = Navalha->new(
	{	
		port	=> 12345,
		listen	=> 500,
		host	=> 'localhost',
		pid_file	=> "/var/run/navalha-12345.pid",
		user	=> 'root',
		group	=> 'root',
		background	=> 0,
		setsid	=> 1,
	}
);
$navalha->run();
close(LOG);
exit;

sub mux_input {
	my ($self, $mux, $fh, $in_ref) = @_;

	while( $$in_ref =~ s/^([^\n]*)\n//o ) {
		next unless defined $1;
		my $temp_mux_in = $1;
		if( $temp_mux_in =~ /([^=]+)=(.*)/o ) {
			$request{substr($1, 0, 255)} = substr($2, 0, 255);
			print $fh "$_ = " . $request{$_} foreach (keys %request);
		} elsif ( $temp_mux_in eq '' ) {
			print $fh "request vazio\n";
			}
		%request = ();

		}

}

